package test;

import java.nio.file.Paths;
import java.nio.file.Path;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Stream;

public class FileWriter implements Runnable {
    private Path path;

    public FileWriter(Path path) {
        this.path = path;
    }

    public void run() {
        try (Stream<String> lines = getLines()) {
            lines.forEach(line -> {
                // 写入每一行数据到文件
                // ...
            });
        }
    }

    private Stream<String> getLines() {
        // 从某个数据源中获取数据，并返回一个字符串流
        // ...
        return null;
    }

    public static void main(String[] args) {
        ExecutorService executor = Executors.newFixedThreadPool(4);
        Path[] files = {Paths.get("output1.txt"), Paths.get("output2.txt"), Paths.get("output3.txt")};

        for (Path file : files) {
            executor.execute(new FileWriter(file));
        }

        executor.shutdown();
    }
}